package com.example.demo.Service;

import com.example.demo.Dao.UserBook;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Controller;


//Spring存对象

//这里往Spring放入了UserBook这个类的两个对象，还有String类的两个对象
@Configuration
public class UseService {


    //这个加上Bean就是把这个方法返回的这个对象放入Spring里了；（Bean为方法注解）
    @Bean
    public UserBook userBook(){
        UserBook userBook = new UserBook();
       userBook.setBookName("西游记");
        userBook.setAuthor("吴承恩");
       userBook.setPrice(56);
        return userBook;
    }
    @Bean
    public String name(){
        return "zhangsan";
    }
    @Bean
    public String name2(){
        return "wangwu";
    }

    @Primary
    @Bean
    public UserBook userBook1(String name){
        UserBook userBook1 = new UserBook();
        userBook1.setBookName(name);
       userBook1.setAuthor("罗贯中");
       userBook1.setPrice(60);
        return userBook1;
    }
    public void gacc(){
        System.out.println("11144");
    }


}
